//package com.plian.system.service.dg.impl;
//
//import com.plian.system.common.status.CustomCode;
//import com.plian.system.constant.sys.FormTypeConstant;
//import com.plian.system.entity.dg.EnterpriseSystem;
//import com.plian.system.mapper.dg.EnterpriseSystemMapper;
//import com.plian.system.model.CommonCode;
//import com.plian.system.model.R;
//import com.plian.system.mybatis.base.BaseServiceImpl;
//import com.plian.system.service.dg.IEnterpriseSystemService;
//import com.plian.system.service.sys.file.FileService;
//import com.plian.system.wrapper.dg.EnterpriseSystemWrapper;
//import lombok.AllArgsConstructor;
//import org.springframework.stereotype.Service;
//import org.springframework.transaction.annotation.Transactional;
//
//import java.util.Date;
//import java.util.Optional;
//
//
//@Service
//@AllArgsConstructor
//public class EnterpriseSystemServiceImpl extends BaseServiceImpl<EnterpriseSystemMapper, EnterpriseSystem> implements IEnterpriseSystemService {
//
//    private final FileService fileService;
//    private EnterpriseSystemWrapper esWrapper;
//
//    @Override
//    @Transactional(rollbackFor=RuntimeException.class)
//    public boolean submit(EnterpriseSystem enterpriseSystem) {
//            boolean result = saveOrUpdate(enterpriseSystem);
//            return result;
//    }
//
//    @Override
//    public boolean saveOrUpdate(EnterpriseSystem epsys){
//        boolean flag = false;
//        if(!Optional.ofNullable(epsys.getId()).isPresent()){
//            flag = true;
//            epsys.setFormType(String.valueOf(FormTypeConstant.DG_COMPANY_SYSTEM_LIBRARY));
//        }
//        boolean result = super.saveOrUpdate(epsys);
//        if (flag){
//            fileService.saveAll(String.valueOf(epsys.getId()), epsys.getDocList());
//        }else {
//            fileService.edit(String.valueOf(epsys.getId()), epsys.getDocList());
//        }
//        return result;
//    }
//
//    public R failure(EnterpriseSystem epsys) {
//
//        if (!Optional.ofNullable(epsys.getId()).isPresent()){
//            return new R(CustomCode.builder().message("该制度不存在").code(1999).success(false).build());
//        }
//
//        EnterpriseSystem detail = getById(epsys.getId());
//        if (Optional.ofNullable(detail.getSystemStatus()).isPresent() &&detail.getSystemStatus() != 1){
//            return new R(CustomCode.builder().message("该制度已失效").code(1999).success(false).build());
//        }
//
//        if(!Optional.ofNullable(epsys.getDeadTime()).isPresent()){
//            detail.setDeadTime(new Date());
//        }else{
//            detail.setDeadTime(epsys.getDeadTime());
//        }
//        detail.setSystemStatus(2);
//        return  updateById(detail) ? new R(CommonCode.SUCCESS) : new R(CommonCode.FAIL);
//    }
//
//
//
//}
